package 力扣日常刷题.木22一月.第06天0114;

import java.util.Arrays;

/**
 * @author 帅小伙
 * @date 2022/1/14
 * @description
 * 深刻理解   因数相乘
 */
public class Demo05中等超级丑数 {

    public int nthSuperUglyNumber1(int n, int[] primes) {
        int[] dp = new int[n+1];
        int m = primes.length;
        int[] nums = new int[m];
        int[] count = new int[m];

        Arrays.fill(nums,1);
        for (int i = 1; i <= n; i++) {
            int minNum = Arrays.stream(nums).min().getAsInt();
            dp[i] = minNum;
            for (int j = 0; j < m; j++) {
                if(nums[j] == minNum){
                    count[j]++;
                    nums[j] = dp[count[j]] * primes[j];
                }
            }
        }
        return dp[n];
    }

}
